"""
风格服务模块
"""

from typing import List, Optional
from loguru import logger

from ..models.story_model import StoryStyle


class StyleService:
    """风格服务类"""

    def __init__(self):
        self.styles: List[StoryStyle] = []
        self._init_default_styles()

    def _init_default_styles(self):
        """初始化默认风格"""
        default_styles = [
            StoryStyle(
                id=1,
                name="水浒风格",
                description="基于《水浒传》的诙谐有趣风格",
                tone="诙谐有趣",
                target_audience="儿童",
                focus="好汉之间的感情",
                characters="36天罡星为主，可带72地煞星",
                length_limit=3000,
                bilingual=True
            ),
            StoryStyle(
                id=2,
                name="通用教育风格",
                description="温暖有趣的教育故事风格",
                tone="温暖有趣",
                target_audience="儿童",
                focus="教育价值",
                characters="通用角色",
                length_limit=2000,
                bilingual=False
            )
        ]
        
        for style in default_styles:
            self.styles.append(style)

    def get_style_by_id(self, style_id: int) -> Optional[StoryStyle]:
        """根据ID获取风格"""
        for style in self.styles:
            if style.id == style_id:
                return style
        return None

    def get_all_styles(self) -> List[StoryStyle]:
        """获取所有风格"""
        return self.styles

    def add_style(self, style: StoryStyle) -> bool:
        """添加新风格"""
        try:
            style.id = len(self.styles) + 1
            self.styles.append(style)
            logger.info(f"风格添加成功: {style.name}")
            return True
        except Exception as e:
            logger.error(f"风格添加失败: {str(e)}")
            return False 